package com.zhiche.lisa.lspm.controller;

import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.lspm.service.otm.IOtmLisaCarrierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/otm")
@Api(value = "/otm", description = "司机接口", tags = {"司机接口"})
public class OtmTransController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OtmTransController.class);

    @Autowired
    private IOtmLisaCarrierService otmLisaCarrierService;

    @PostMapping(value = "/callback")
    @ApiOperation(value = " otm 回调", notes = " otm 回调", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse otmCallback(@RequestBody String returnMessage) {
        LOGGER.info("OtmTransController.otmCallback（ otm 回调） params : {} ", returnMessage);

        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),CommonEnum.SUCCESS.getText(),null);
        try {
            otmLisaCarrierService.updateCallbackResult(returnMessage);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.otmCallback ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.otmCallback ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }
}
